﻿using BusinessLogic;
using Common;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AppAdmin.Controllers
{
    public class CommentController : Controller
    {
        //
        // GET: /Comment/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Details()
        {
            return View();
        }
        public ActionResult GetFormJson(string keyValue)
        {
            string star_str = "";
            V_Comment model = new UserCommentLogic().GetFormInfo(keyValue);
            switch (model.Star)
            {
                case 1: star_str = "一星"; break;
                case 2: star_str = "二星"; break;
                case 3: star_str = "三星"; break;
                case 4: star_str = "四星"; break;
                case 5: star_str = "五星"; break;
            }
            return Content(new  { UserTel = model.UserTel, CommentDate = Convert.ToDateTime(model.CommentDate).ToString("yyyy-MM-dd HH:mm:ss"), Star = star_str, Content = model.Content }.ToJson());
           // return Json(new { UserTel = model.UserTel, CommentDate = Convert.ToDateTime(model.CommentDate).ToString("yyyy-MM-dd HH:mm:ss"), Star = star_str, Content = model.Content });
        }

        public ActionResult DeleteForm(string keyValue)
        {
            List<string> strList = new List<string>();
            UserCommentLogic bll = new UserCommentLogic();
            if (keyValue.IndexOf(',') < 0)
            {
                strList.Add(keyValue);
            }
            else
            {
                string[] strs = keyValue.Split(',');
                for (int i = 0; i < strs.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strs[i]) && CommonFun.IsGuidByReg(strs[i]))
                    {
                        strList.Add(strs[i]);
                    }
                }
            }
            bll.DelInfo(strList);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }

        public ActionResult Agree(string keyValue)
        {
            List<string> strList = new List<string>();
            UserCommentLogic bll = new UserCommentLogic();
            if (keyValue.IndexOf(',') < 0)
            {
                strList.Add(keyValue);
            }
            else
            {
                string[] strs = keyValue.Split(',');
                for (int i = 0; i < strs.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strs[i]) && CommonFun.IsGuidByReg(strs[i]))
                    {
                        strList.Add(strs[i]);
                    }
                }
            }
            bll.Agree(strList);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }

        public ActionResult Refuse(string keyValue)
        {
            List<string> strList = new List<string>();
            UserCommentLogic bll = new UserCommentLogic();
            if (keyValue.IndexOf(',') < 0)
            {
                strList.Add(keyValue);
            }
            else
            {
                string[] strs = keyValue.Split(',');
                for (int i = 0; i < strs.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strs[i]) && CommonFun.IsGuidByReg(strs[i]))
                    {
                        strList.Add(strs[i]);
                    }
                }
            }
            bll.Refuse(strList);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }
    }
}
